left-square-bracketright-square-bracket
Type
keyword
Summary
The square bracket characters [ ] surround the element name in an array reference.
Syntax
[]
Description
Use square brackets [ ] to specify which element in an array you are referring to.
You access an element of an array by using the name of the array, along with the key in square brackets:
put \"A\" into myList[\"firstLetter\"]
put \"B\" into myList[\"secondLetter\"]
put \"C\" into myList[\"thirdLetter\"]
get myList[\"secondLetter\"] -- yields \"B\"
Square brackets must be used in pairs, each [ with a matching ]. Using a single square bracket does not cause an error, but the bracket is interpreted as part of the variable name, rather than as the marker for the key of an array reference.
Arrays in LiveCode are associative (also known as hash tables). This means that when an array element is accessed using square bracket notation, the value in between the brackets is used to "look up" the element, and is not a numeric index as in C, Pascal and other languages. Of course it is still possible to use numbers as array keys, but LiveCode internally converts these to strings before retrieving the array elements.
Examples
put thisValue into myArray["someKey"]
if myArray["someOtherKey"] is "A" then beep
Related
command: split
function: arrayEncode
glossary: array, variable, error, key
keyword: element
operator: left-round-bracketright-round-bracket
Compatibility and Support
Introduced
LiveCode 1.0
OS
mac
windows
linux
ios
android
Platforms
desktop
server
mobile